home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / chdir.c < prev    next >
C/C++ Source or Header  |  1993-07-06  |  859b  |  45 lines

  1. #include <errno.h>
  2. #include <osbind.h>
  3. #include <stddef.h>
  4. #include <assert.h>
  5. #include <ctype.h>
  6. #include <limits.h>
  7. #include <unistd.h>
  8. #include "lib.h"
  9.  
  10. /***************************************************************
  11. chdir: change the directory and (possibly) the drive.
  12. By ERS: it's in the public domain.
  13. ****************************************************************/
  14.  
  15. int chdir(dir)
  16. const char *dir;
  17. {
  18.     int drv, old;
  19.     int r;
  20.     char tmp[PATH_MAX];
  21.     register char *d;
  22.  
  23.     assert ((dir != NULL));
  24.  
  25.     (void)_unx2dos(dir, tmp);    /* convert Unix filename to DOS */
  26.     d = tmp;
  27.     old = Dgetdrv();
  28.     if (*d && *(d+1) == ':') {
  29.         drv = toupper(*d) - 'A';
  30.         d+=2;
  31.         (void)Dsetdrv(drv);
  32.     }
  33.  
  34.     if (!*d) {        /* empty path means root directory */
  35.         *d = '\\';
  36.         *(d+1) = '\0';
  37.     }
  38.     if ((r = Dsetpath(d)) < 0) {
  39.         (void)Dsetdrv(old);
  40.         errno = -r;
  41.         return -1;
  42.     }
  43.     return 0;
  44. }
  45.